﻿using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using wt.wine.Application.Common.Interfaces;
using wt.wine.Application.Common.Models;

namespace wt.wine.Application.ManageDevicetable.Queries
{

    /// <summary>
    /// 添加员工 获取设备列表
    /// </summary>
    public class GetDeviceByAddUserQueries : IRequest<Json<List<GetDeviceByAddUserDTO>>>
    {

    }
    public class GetDeviceByAddUserQueriesHandler : IRequestHandler<GetDeviceByAddUserQueries, Json<List<GetDeviceByAddUserDTO>>>
    {
        private readonly ICurrentUserService _icurrentuserServices;
        private readonly IDevicetableRepository _devicetableRepository;
        public GetDeviceByAddUserQueriesHandler(ICurrentUserService icurrentuserServices, IDevicetableRepository devicetableRepository)
        {
            _icurrentuserServices = icurrentuserServices;
            _devicetableRepository = devicetableRepository;
        }
        public async Task<Json<List<GetDeviceByAddUserDTO>>> Handle(GetDeviceByAddUserQueries request, CancellationToken cancellationToken)
        {
            int userid = _icurrentuserServices.GetUserId();

            var list = await _devicetableRepository.GetDeviceByAddUser(userid, cancellationToken);
            if (!(list != null && list.Any()))
            {
                list = new List<GetDeviceByAddUserDTO>() { };
            }
            return Json<List<GetDeviceByAddUserDTO>>.Success("查询成功", list);
       
        }
    }
}
